package org.szgb.console.ht.electricity.entity;

import com.fasterxml.jackson.annotation.JsonFormat;
import io.swagger.v3.oas.annotations.media.Schema;
import lombok.Data;
import lombok.EqualsAndHashCode;
import org.springframework.format.annotation.DateTimeFormat;
import org.szgb.console.utils.PageDto;
import org.szgb.core.base.entity.BeanEntity;

import java.io.Serial;
import java.time.LocalDateTime;
import java.util.List;

@EqualsAndHashCode(callSuper = true)
@Data
public class HtElectricitySettlementBillModel extends BeanEntity<HtElectricitySettlementBillModel> {
    @Serial
    private static final long serialVersionUID = 1L;
    private String name;
    private Integer type;
    private String customerName;
    private String projectName;
    private String contractNoAndName;
    private String partyAName;
    private String partyBName;
    private String partyCName;
    private String remark;

    public HtElectricitySettlementBillModel() {
    }

    public HtElectricitySettlementBillModel(String id) {
        this.setId(id);
    }

    public HtElectricitySettlementBillModel(HtElectricitySettlementBillModel.HtElectricitySettlementBillModelFindDto htElectricitySettlementBillModelFindDto) {
        this.setId(htElectricitySettlementBillModelFindDto.getId());
        this.setName(htElectricitySettlementBillModelFindDto.getName());
        this.setPageDto(htElectricitySettlementBillModelFindDto.getPageDto());
    }

    public HtElectricitySettlementBillModel(HtElectricitySettlementBillModel.HtElectricitySettlementBillModelSaveDto htElectricitySettlementBillModelSaveDto) {
        this.setId(htElectricitySettlementBillModelSaveDto.id);
        this.setName(htElectricitySettlementBillModelSaveDto.name);
        this.setType(htElectricitySettlementBillModelSaveDto.type);
        this.setCustomerName(htElectricitySettlementBillModelSaveDto.customerName);
        this.setProjectName(htElectricitySettlementBillModelSaveDto.projectName);
        this.setContractNoAndName(htElectricitySettlementBillModelSaveDto.contractNoAndName);
        this.setPartyAName(htElectricitySettlementBillModelSaveDto.partyAName);
        this.setPartyBName(htElectricitySettlementBillModelSaveDto.partyBName);
        this.setPartyCName(htElectricitySettlementBillModelSaveDto.partyCName);
        this.setRemark(htElectricitySettlementBillModelSaveDto.remark);
    }

    public HtElectricitySettlementBillModel.HtElectricitySettlementBillModelView toHtElectricitySettlementBillModelView() {
        return new HtElectricitySettlementBillModel.HtElectricitySettlementBillModelView(this);
    }

    @Data
    @Schema(title = "电量结算单模板信息", description = "电量结算单模板信息")
    public static class HtElectricitySettlementBillModelView {
        @Schema(description = "ID")
        private String id;
        @Schema(description = "模板名称")
        private String name;
        @Schema(description = "模板类型（1：4号线供电；2：6号线厦门段供电；3：6号线漳州段供电）")
        private Integer type;
        @Schema(description = "客户名称")
        private String customerName;
        @Schema(description = "项目名称")
        private String projectName;
        @Schema(description = "合同编号和名称")
        private String contractNoAndName;
        @Schema(description = "甲方名称")
        private String partyAName;
        @Schema(description = "乙方名称")
        private String partyBName;
        @Schema(description = "丙方名称")
        private String partyCName;
        @Schema(description = "说明")
        private String remark;
        @JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss", timezone = "GMT+8")
        @DateTimeFormat(pattern = "yyyy-MM-dd HH:mm:ss")
        @Schema(description = "创建时间")
        private LocalDateTime createdAt;
        @JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss", timezone = "GMT+8")
        @DateTimeFormat(pattern = "yyyy-MM-dd HH:mm:ss")
        @Schema(description = "更新时间")
        private LocalDateTime updatedAt;
        @Schema(description = "创建人id")
        private String createdById;
        @Schema(description = "创建人姓名")
        private String createdByName;
        @Schema(description = "更新人id")
        private String updatedById;
        @Schema(description = "更新人姓名")
        private String updatedByName;

        public HtElectricitySettlementBillModelView(HtElectricitySettlementBillModel htElectricitySettlementBillModel) {
            this.id = htElectricitySettlementBillModel.getId();
            this.name = htElectricitySettlementBillModel.getName();
            this.type = htElectricitySettlementBillModel.getType();
            this.customerName = htElectricitySettlementBillModel.getCustomerName();
            this.projectName = htElectricitySettlementBillModel.getProjectName();
            this.contractNoAndName = htElectricitySettlementBillModel.getContractNoAndName();
            this.partyAName = htElectricitySettlementBillModel.getPartyAName();
            this.partyBName = htElectricitySettlementBillModel.getPartyBName();
            this.partyCName = htElectricitySettlementBillModel.getPartyCName();
            this.createdAt = htElectricitySettlementBillModel.getCreatedAt();
            this.updatedAt = htElectricitySettlementBillModel.getUpdatedAt();
            this.remark = htElectricitySettlementBillModel.getRemark();
            if (htElectricitySettlementBillModel.getCreatedBy() != null) {
                this.createdById = htElectricitySettlementBillModel.getCreatedBy().getId();
                this.createdByName = htElectricitySettlementBillModel.getCreatedBy().getName();
            }
            if (htElectricitySettlementBillModel.getUpdatedBy() != null) {
                this.updatedById = htElectricitySettlementBillModel.getUpdatedBy().getId();
                this.updatedByName = htElectricitySettlementBillModel.getUpdatedBy().getName();
            }
        }

        public static List<HtElectricitySettlementBillModel.HtElectricitySettlementBillModelView> getViewListFromList(List<HtElectricitySettlementBillModel> htElectricitySettlementBillModelList) {
            return htElectricitySettlementBillModelList.stream().map(HtElectricitySettlementBillModel.HtElectricitySettlementBillModelView::new).toList();
        }
    }

    @Data
    @Schema(title = "电量结算单模板查询表单", description = "电量结算单模板查询参数")
    public static class HtElectricitySettlementBillModelFindDto {
        @Schema(description = "ID")
        private String id;
        @Schema(description = "模板名称")
        private String name;
        @Schema(description = "分页信息")
        private PageDto pageDto;

        public HtElectricitySettlementBillModel toHtElectricitySettlementBillModel() {
            return new HtElectricitySettlementBillModel(this);
        }
    }

    @Data
    @Schema(title = "电量结算单模板保存表单", description = "电量结算单模板保存参数")
    public static class HtElectricitySettlementBillModelSaveDto {
        @Schema(description = "id(如为空则为新增数据)")
        private String id;
        @Schema(description = "模板名称")
        private String name;
        @Schema(description = "模板类型")
        private Integer type;
        @Schema(description = "客户名称")
        private String customerName;
        @Schema(description = "项目名称")
        private String projectName;
        @Schema(description = "合同编号和名称")
        private String contractNoAndName;
        @Schema(description = "甲方名称")
        private String partyAName;
        @Schema(description = "乙方名称")
        private String partyBName;
        @Schema(description = "丙方名称")
        private String partyCName;
        @Schema(description = "说明")
        private String remark;
        public HtElectricitySettlementBillModel toHtElectricitySettlementBillModel() {
            return new HtElectricitySettlementBillModel(this);
        }
    }
}
